package prictice.hbase.state;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HTable;

import java.io.IOException;
import java.io.Serializable;

/**
 * @Package prictice.hbase.state
 * @Description:
 * @Author elwyn
 * @Date 2017/9/21 22:49
 * @Email elonyong@163.com
 */
public class HTableConnect implements Serializable {
    private static final long serialVersionUID = 6186700217574334043L;
    private Configuration configuration;
    protected HTable hTable;
    private String tableName;

    public HTableConnect(TupleTableConfig config) throws Exception {
        this.tableName = config.getTableName();
        this.configuration = HBaseConfiguration.create();
        this.configuration.set("hbase.zookeeper.property.clientPort", "2181");
        //配置zookeeper地址,多个用逗号分隔
        this.configuration.set("hbase.zookeeper.quorum", "hadoop-senior.ibeifeng.com,hadoop-senior02.ibeifeng.com");
/*        String filePathString = "hbase-site.xml";
        Path path = new Path(filePathString);
        this.configuration.addResource(path);*/
        this.hTable = new HTable(this.configuration, this.tableName);

    }

    public Configuration getConfiguration() {
        return configuration;
    }

    public void setConfiguration(Configuration configuration) {
        this.configuration = configuration;
    }

    public HTable gethTable() {
        return hTable;
    }

    public void sethTable(HTable hTable) {
        this.hTable = hTable;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public void close() throws IOException {
        this.hTable.close();
    }

}
